﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Admin_DevWork_Query : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string uername = "";
        uername = Request.QueryString["id"].ToString();
        string id = Fnum.Text.Trim();
        string tabelall = "<table class='layui-table' width='80%'><thead><tr><th>登录名</th><th>登录密码</th><th>姓名</th><th>性别</th><th>联系电话</th><th>邮箱</th><th>删除</th></tr></thead>";
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringProManage"].ConnectionString;
        try
        {
            conn.Open();

            SqlCommand cmddel = new SqlCommand();
            string SQLdel = "update Users set flag=0 where (uername=@uername)";
            cmddel.Connection = conn;
            cmddel.CommandText = SQLdel;
            cmddel.CommandType = CommandType.Text;
            //提交参数 SQL 语句中必须要有@参数
            SqlParameter pname = new SqlParameter("@uername", SqlDbType.NVarChar, 10);
            pname.Value = uername;
            cmddel.Parameters.Add(pname);
            cmddel.ExecuteNonQuery();

            SqlCommand cmd = new SqlCommand();
            string SQL = "select uername,password,name,sex,tel,email from Users where ([uername]  LIKE '%' + @uername + '%') and flag=1 and usertype=0";
            cmd.Connection = conn;
            cmd.CommandText = SQL;
            cmd.CommandType = CommandType.Text;
            //提交参数 SQL 语句中必须要有@参数
            SqlParameter pusername = new SqlParameter("@uername", SqlDbType.NVarChar, 10);
            pusername.Value = id;
            cmd.Parameters.Add(pusername);

            int k = 0;
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                int fieldcount = reader.FieldCount;      //取字段总数
                if (!reader.HasRows)            //有数据  ---行
                {
                    Label1.Text = "<table class='layui-table' style='width: 70%; margin-left:15% '><tr><td>没有数据</td></tr>";
                }
                else
                {
                    string trd = "<tbody>";                     //存储数据
                    while (reader.Read())               //当有数据可读时
                    {
                        trd += "<tr>";         //数据行开始，行以tr起
                        for (int i = 0; i < fieldcount; i++)
                        {   //每一列的内容
                            trd += "<td>" + reader[i].ToString() + "</td>";
                        }
                        trd += "<td><a title='删除'  href = 'Admin_DevWork_Query.aspx?id=" + reader[0].ToString() + "'><i class='layui-icon'>&#xe640;</i></td></tr>";           //行结束
                        k = k + 1;
                    }
                    //Response.Write(tabelall + trd + "</tbody></table>");

                    Label1.Text = tabelall + trd + "</tbody></table>";
                    //MsgNum.Text = k.ToString();

                }
            }
        }


        finally
        {
            conn.Close();
        }

    }
}